package com.jnxx.task.controller;

import com.jnxx.task.domain.Shop;
import com.jnxx.task.service.IShopService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * shopController
 * 
 * @author ruoyi
 * @date 2024-01-08
 */
@RestController
@RequestMapping("/api/shop")
public class ShopController extends BaseController
{
    @Autowired
    private IShopService shopService;

    /**
     * 查询shop列表
     */
//    @PreAuthorize("@ss.hasPermi('api:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(Shop shop)
    {
        startPage();
        List<Shop> list = shopService.selectShopList(shop);
        return getDataTable(list);
    }

    /**
     * 导出shop列表
     */
//    @PreAuthorize("@ss.hasPermi('api:shop:export')")
    @Log(title = "shop", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Shop shop)
    {
        List<Shop> list = shopService.selectShopList(shop);
        ExcelUtil<Shop> util = new ExcelUtil<Shop>(Shop.class);
        util.exportExcel(response, list, "shop数据");
    }

    /**
     * 获取shop详细信息
     */
//    @PreAuthorize("@ss.hasPermi('api:shop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopService.selectShopById(id));
    }

    /**
     * 新增shop
     */
//    @PreAuthorize("@ss.hasPermi('api:shop:add')")
    @Log(title = "shop", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Shop shop)
    {
        return toAjax(shopService.insertShop(shop));
    }

    /**
     * 修改shop
     */
//    @PreAuthorize("@ss.hasPermi('api:shop:edit')")
    @Log(title = "shop", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Shop shop)
    {
        return toAjax(shopService.updateShop(shop));
    }

    /**
     * 删除shop
     */
//    @PreAuthorize("@ss.hasPermi('api:shop:remove')")
    @Log(title = "shop", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shopService.deleteShopByIds(ids));
    }


    @GetMapping("/getAll")
    public AjaxResult getAll()
    {
        return success(shopService.selectAllShop());
    }

}
